package com.wcar.user.service.impl;

import com.alibaba.fastjson.JSON;
import com.wcar.common.entity.FrontUser;
import com.wcar.common.entity.User;
import com.wcar.common.util.WebUtil;
import com.wcar.common.vo.Result;
import com.wcar.user.dao.FrontUserDao;
import com.wcar.user.service.FrontUserServiceImpl;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

/**
 * @program: four-wcar-idea
 * @description:
 * @author: 吴朝阳
 * @create: 2024-06-12 19:20
 **/
@Service
public class FrontUserService implements FrontUserServiceImpl {
    @Autowired
    private FrontUserDao frontUserDao;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Override
    public Result<FrontUser> updatefronUser(FrontUser frontUser) {
        String token = WebUtil.getToken();
        redisTemplate.delete("font:login:"+token);
        frontUserDao.updateById(frontUser);
        FrontUser frontUser1 = frontUserDao.selectById(frontUser.getUserId());
        System.out.println(frontUser1.getUserName());
        ValueOperations<String, String> stringStringValueOperations = redisTemplate.opsForValue();
        stringStringValueOperations.set("font:login:"+token, JSON.toJSONString(frontUser1));
        return new Result<>(2000,"修改个人信息成功",frontUser);
    }


}
